<template>
	<view class="register-view col-arrange">
		<!-- <view><text class="tip-text">用户名&nbsp;&nbsp;：</text></view> -->
		<input class="theme-input" id="username" type="text" v-model="username" placeholder="用户名">
		<input class="theme-input" id="password" password="true" v-model="password" placeholder="密码">
		<input class="theme-input" id="chePassword" password="true" v-model="chePassword" placeholder="确认密码">
		<input class="theme-input"  v-model="name" placeholder="真实姓名">
		
		<textarea class="theme-input" maxlength="100" placeholder="个人介绍，至多100个字" v-model="intro"></textarea>
		<!-- <view><text class="tip-text" style="color:red">{{errorText}}</text></view> -->
		<button type="primary" @click="submit">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username : "",
				password : "",
				chePassword : "",
				name : "",
				intro : "",
				nextUrl : 'main'
			}
		},
		onLoad(option) {
			if(option.nextUrl != null){
				this.nextUrl = option.nextUrl;
			}
		},
		methods: {
			
			submit : function(){
				if(this.username == "" || this.password == "" || this.name == "" || this.intro == ""){
					uni.showModal({
						title : '错误',
						content : '请完善关键信息',
						showCancel : false
					})
					return;
				}
				if(this.password != this.chePassword){
					uni.showModal({
						title : '错误',
						content : '两次密码输入不一致',
						showCancel : false
					})
					return;
				}
				var param = {'username':this.username,'password':this.password,'name':this.name,'intro':this.intro};
				// console.log(param);
				var vm = this;
				this.$post(this.userurl + '/user/register',param,function(res){
					var data = res.data;
					// console.log(data)
					if(data.code != 0){
						vm.errorText = data.message;
						return;
					}
					var token = {'userId' : param.username , 'token' : data.token};
					// console.log(token);
					uni.setStorage({
						key : 'userToken',
						data : token
					})
					// 到达用户个人页面
					uni.navigateTo({
						url : vm.nextUrl
					})
				},true);
				
			}
		}
	}
</script>

<style>
	@import "../../common/zcss.css";
	/* page{
		background-color: white;
	} */
	/* input{
		margin-top:4upx;
		background-color: aqua;
		height:10upx;
	} */
	input{
		margin-top:25upx;
		margin-bottom: 25upx;
		/* background-color: rgba(231, 226, 226, 0.568); */
		
		height:40upx;
		width: 400upx;
		padding: 20upx;
		padding-left: 30upx;
		border-radius: 50upx;
		/* border-bottom: 1upx solid black; */
	}
	textarea{
		/* margin-top:4upx;
		background-color: aqua; */
		margin-top:25upx;
		margin-bottom: 25upx;
		width: 400upx;
		height:330upx;
		/* background-color: rgba(231, 226, 226, 0.568); */
		padding: 20upx;
		padding-left: 30upx;
		border-radius: 50upx;
	}
	.register-view{
		width: 100%;
		top:200upx;
		left:150upx;
		position: absolute;
		/* text-align: center; */
		/* flex-direction: column; */
	}
	button{
		margin-top: 20upx;
		/* margin-bottom: 300upx; */
		background-color: blue;
		width: 440upx; 
		/* position: absolute; */
		border-radius: 50upx;
		margin-right: 390upx;
	}
</style>
